package q145

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
//递归方法进行后序遍历
func postorderTraversal(root *TreeNode) []int {
	res:=[]int{}
	if root==nil{
		return res
	}

	if root.Left!=nil{
		left:=postorderTraversal(root.Left)
		for _,v:=range left{
			res=append(res,v)
		}
	}

	if root.Right!=nil{
		right:=postorderTraversal(root.Right)
		for _,v:=range right{
			res=append(res,v)
		}
	}
	res=append(res, root.Val)
	return res
}